package com.yaozheng.vocationaltraining.view;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.activity.BaseActivity;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.TypeUtils;

import android.content.Context;
import android.content.Intent;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

/**
 * 一项资料
 *
 * @author Administrator
 */
@EViewGroup(R.layout.item_my_user_info_data)
public class ItemMyUserInfoDataView extends LinearLayout {
    @ViewById
    TextView itemMyUserInfoDataName, itemMyUserInfoDataContent;
    @ViewById
    ImageView itemMyUserInfoDataRightImage, itemMyUserInfoDataImage;
    /**
     * 数据
     */
    JSONObject itemData;

    public ItemMyUserInfoDataView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemMyUserInfoDataView(Context context) {
        super(context);
    }

    /**
     * 加载数据
     *
     * @param position
     * @param itemData
     */
    public void loadData(int position, JSONObject itemData) {
        this.itemData = itemData;

        itemMyUserInfoDataName.setText(TypeUtils.getJsonString(itemData, "name"));

        itemMyUserInfoDataImage.setImageResource(TypeUtils.getJsonInteger(itemData, "icon_left", R.drawable.icon_username));
        String nameKey = TypeUtils.getJsonString(itemData, "nameKey");
//        password
        if ("password".equals(nameKey)) {
            itemMyUserInfoDataContent.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            itemMyUserInfoDataContent.setText("12345678");
        } else {
            itemMyUserInfoDataContent.setInputType(InputType.TYPE_CLASS_TEXT);
            itemMyUserInfoDataContent.setText(TypeUtils.getJsonString(itemData, "showValue", ""));
        }
        if (2 == TypeUtils.getJsonInteger(itemData, "isUpdate", 1)) {
            itemMyUserInfoDataRightImage.setVisibility(View.VISIBLE);

        } else {
            itemMyUserInfoDataRightImage.setVisibility(View.INVISIBLE);

        }

    }


}
